/*************************************************************************
	> File Name: 026.HZOJ-640.食物链计数.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 一  6/28 13:39:41 2021
 ************************************************************************/

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

struct edge {
    int e, next;
};

int n, m, head[5005], ans[5005], in_degree[5005], out_degree[5005], fin;
edge edg[500005];

int main() {
    memset(head, -1, sizeof(head));
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        edg[i].e = b;
        edg[i].next = head[a];
        head[a] = i;
        //统计入度和出度
        in_degree[b]++;
        out_degree[a]++;
    }
    queue<int> que; //存储入度为0的点
    for (int i = 1; i <= n; i++) {
        if (in_degree[i] == 0) {
            que.push(i);
            ans[i] = 1; //起点的链的数量初始化为1
        }
    }
    while (!que.empty()) {
        int t = que.front();
        que.pop();
        for (int i = head[t]; i != -1; i = edg[i].next) {
            int e = edg[i].e;
            in_degree[e]--;
            ans[e] += ans[t]; 
            ans[e] %= 100000007;
            if (in_degree[e] == 0) {
                que.push(e);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (out_degree[i] == 0) { //出度为0，表示为终点
            fin += ans[i];
            fin %= 100000007;
        }
    }
    cout << fin << endl;
    return 0;
}
